package com.gqzdev.xblog.config;

import com.gqzdev.xblog.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebConfig
 * @Description
 * @Author ganquanzhong
 * @Date2020/5/31 16:16
 * @Version
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        configurer.setUseSuffixPatternMatch(true).setUseTrailingSlashMatch(true);
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/system/**")
                //这个是用于拦截请求，获取三级菜单
                .addPathPatterns("/admin/**/list")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/system/login")
                //验证码url
                .excludePathPatterns("/system/get_cpacha");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String osName = System.getProperties().getProperty("os.name");
        if(osName.equals("Linux"))
        {
            registry.addResourceHandler("/upload/**")
                    .addResourceLocations("file:/upload/title/","file:/upload/ad/","file:/upload/");
        }else {
            registry.addResourceHandler("/upload/**")
                    .addResourceLocations("file:E:/upload/title/","file:E:/upload/ad/","file:E:/upload/");
        }
    }
}
